package other

import org.apache.spark.{SparkConf, SparkContext}

object TestNew {

  // 设置 Hadoop 相关环境变量
  System.setProperty("hadoop.home.dir", "F:\\Hadoop\\hadoop-3.3.6-windows-bin")
  System.setProperty("HADOOP_USER_NAME", "root")

  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setMaster("local[*]").setAppName("TestNew")
    val sc = new SparkContext(conf)

    sc.setLogLevel("error")
    val arr = Array("hello spark", "hello java", "hello hive")
    val arrRDD = sc.parallelize(arr)
    arrRDD.flatMap(_.split(" ")).map((_, 1)).reduceByKey(_ + _).sortBy(_._2).foreach(println(_))
  }

}
